//
//  TaskManagerScreenView.m
//  LogisticsSupplier
//
//  Created by 吕晶 on 2021/3/19.
//  Copyright © 2021 吕晶. All rights reserved.
//

#import "TaskManagerScreenView.h"
#import "BRDatePickerView.h"

@interface TaskManagerScreenView ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic, strong) UIView *bgView;
@property (nonatomic, strong) UIView *bottomView;
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) TaskManagerSearchModel *currentModel;
@property (nonatomic, strong) NSArray *carRequireArray;

@end

@implementation TaskManagerScreenView

-(NSArray *)carRequireArray {
    if (!_carRequireArray) {
        _carRequireArray = [NSArray array];
    }
    return _carRequireArray;
}

-(TaskManagerSearchModel *)currentModel {
    if (!_currentModel) {
        _currentModel = [TaskManagerSearchModel new];
    }
    return _currentModel;
}

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        self.frame = CGRectMake(0, 0, ScreenW, ScreenH);
        self.backgroundColor = HexColorA(0x000000, 0.5);
        UIButton *btn = [[UIButton alloc] initWithFrame:self.frame];
        [btn addTarget:self action:@selector(bgClick) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:btn];
        [self configUI];
    }
    return self;
}

- (void)configUI {
    self.bgView = [[UIView alloc] initWithFrame:CGRectMake(90, 0, ScreenW - 90, ScreenH)];
    self.bgView.backgroundColor = HexColor(0xffffff);
    [self addSubview:self.bgView];
    
    self.bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, self.bgView.nim_height - 64 - BottomHeight, self.bgView.nim_width, 64 + BottomHeight)];
    self.bottomView.backgroundColor = HexColor(0xffffff);
    [self.bgView addSubview:self.bottomView];
    
    UIButton *resetBtn = [[UIButton alloc] initWithFrame:CGRectMake(15, 10, 68, 44)];
    [resetBtn setTitle:@"重置" forState:0];
    [resetBtn setTitleColor:HexColor(0x585974) forState:0];
    resetBtn.titleLabel.font = BoldFontOfSize(14);
    resetBtn.layer.masksToBounds = YES;
    resetBtn.layer.cornerRadius = 6;
    resetBtn.backgroundColor = HexColor(0xffffff);
    resetBtn.layer.borderColor = HexColor(0xDBDCE6).CGColor;
    resetBtn.layer.borderWidth = 1;
    [resetBtn addTarget:self action:@selector(resetClick) forControlEvents:UIControlEventTouchUpInside];
    [self.bottomView addSubview:resetBtn];
    
    UIButton *sureBtn = [[UIButton alloc] initWithFrame:CGRectMake(resetBtn.nim_right + 10, resetBtn.nim_top, self.bottomView.nim_width - 15 - (resetBtn.nim_right + 10), 44)];
    [sureBtn setTitle:@"确认" forState:0];
    [sureBtn setTitleColor:HexColor(0xffffff) forState:0];
    sureBtn.titleLabel.font = BoldFontOfSize(14);
    sureBtn.layer.masksToBounds = YES;
    sureBtn.layer.cornerRadius = 6;
    sureBtn.backgroundColor = Color_ThemeColor;
    [sureBtn addTarget:self action:@selector(sureClick) forControlEvents:UIControlEventTouchUpInside];
    [self.bottomView addSubview:sureBtn];
    
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 20 + StatusBarHeight, self.bgView.nim_width, self.bgView.nim_height - 20 - StatusBarHeight - self.bottomView.nim_height)];
    self.tableView.backgroundColor = HexColor(0xffffff);
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.bgView addSubview:self.tableView];
}

-(void)setModel:(TaskManagerSearchModel *)model {
    _model = model;
    self.currentModel = model;
    [self.tableView reloadData];
}

- (void)resetClick {
    self.currentModel = [TaskManagerSearchModel new];
    [self.tableView reloadData];
}

- (void)sureClick {
    if (self.finishBlock) {
        self.finishBlock(self.currentModel);
    }
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    TaskManagerScreenViewCell *cell = [TaskManagerScreenViewCell TaskManagerScreenViewCellWithTableView:tableView];
    cell.model = self.currentModel;
    __weak_self;
    cell.danHaoBlock = ^(NSString * _Nonnull str) {
        weakself.currentModel.the_num = str;
    };
    cell.chuFaBlock = ^(NSString * _Nonnull str) {
        weakself.currentModel.s_city = str;
    };
    cell.muDiBlock = ^(NSString * _Nonnull str) {
        weakself.currentModel.r_city = str;
    };
    cell.laiYuanBlock = ^(NSString * _Nonnull str) {
        weakself.currentModel.t_name = str;
    };
    cell.cheLiangBlock = ^{
        UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
        [weakself.carRequireArray enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            UIAlertAction *action1 = [UIAlertAction actionWithTitle:[obj objectForKey:@"name"] style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                weakself.model.car_require = [[obj objectForKey:@"id"] intValue];
                weakself.model.car_require_name = [obj objectForKey:@"name"];
                [weakself.tableView reloadData];
            }];
            [alert addAction:action1];
        }];
        UIAlertAction *cancle = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {

        }];
        [alert addAction:cancle];
        [[FactoryMethod getCurrentVC] presentViewController:alert animated:YES completion:nil];
    };
    cell.pieceMinBlock = ^(NSString * _Nonnull str) {
        weakself.currentModel.pnum_min = str;
    };
    cell.pieceMaxBlock = ^(NSString * _Nonnull str) {
        weakself.currentModel.pnum_max = str;
    };
    cell.weightMinBlock = ^(NSString * _Nonnull str) {
        weakself.currentModel.weight_min = str;
    };
    cell.weightMaxBlock = ^(NSString * _Nonnull str) {
        weakself.currentModel.weight_max = str;
    };
    cell.volumeMinBlock = ^(NSString * _Nonnull str) {
        weakself.currentModel.volume_min = str;
    };
    cell.volumeMaxBlock = ^(NSString * _Nonnull str) {
        weakself.currentModel.volume_max = str;
    };
    cell.beginBlock = ^{
        [BRDatePickerView showDatePickerWithTitle:@"起始时间" dateType:UIDatePickerModeDateAndTime defaultSelValue:nil minDateStr:nil maxDateStr:nil isAutoSelect:YES resultBlock:^(NSString *selectValue) {
            weakself.currentModel.strat_time = selectValue;
            [tableView reloadData];
        }];
    };
    cell.endBlock = ^{
        [BRDatePickerView showDatePickerWithTitle:@"截止时间" dateType:UIDatePickerModeDateAndTime defaultSelValue:nil minDateStr:nil maxDateStr:nil isAutoSelect:YES resultBlock:^(NSString *selectValue) {
            weakself.currentModel.end_time = selectValue;
            [tableView reloadData];
        }];
    };
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    TaskManagerScreenViewCell *cell = [TaskManagerScreenViewCell TaskManagerScreenViewCellWithTableView:tableView];
    cell.model = self.currentModel;
    return cell.height;
}

- (void)bgClick {
    if (self.dismissBlock) {
        self.dismissBlock();
    }
}

- (void)showInView:(UIView *)view {
    [self requestForCarRequire];
    if (!view) {
        return;
    }
    [view addSubview:self];
    [self.bgView setFrame:CGRectMake(ScreenW, 0, ScreenW - 90, ScreenH)];
    [UIView animateWithDuration:0.3 animations:^{
        [self.bgView setFrame:CGRectMake(90, 0, ScreenW - 90, ScreenH)];
    } completion:nil];
}

- (void)requestForCarRequire {
    [HttpRequest PostWithApi:LogisticsSupplierTaskManagerScanCarRequire params:@{} progress:^(NSProgress * _Nonnull progress) {
            
    } success:^(NSURLSessionDataTask * _Nonnull operation, id  _Nonnull responseObject, BOOL code, NSInteger errorCode) {
        if (code) {
            self.carRequireArray = responseObject[@"car_require"];
        }
    } fail:^(NSError * _Nonnull error) {
        
    }];
}

- (void)disMissView {
    [self.bgView setFrame:CGRectMake(90, 0, ScreenW - 90, ScreenH)];
    [UIView animateWithDuration:0.3 animations:^{
        [self.bgView setFrame:CGRectMake(ScreenW, 0, ScreenW - 90, ScreenH)];
    } completion:^(BOOL finished) {
        [self removeFromSuperview];
    }];
}

@end

@interface TaskManagerScreenViewCell ()

@property (nonatomic, strong) UILabel *noTitleLab;
@property (nonatomic, strong) UITextField *noField;
@property (nonatomic, strong) UILabel *lineTitleLab;
@property (nonatomic, strong) UITextField *chuFaField;
@property (nonatomic, strong) UITextField *muDiField;
@property (nonatomic, strong) UILabel *line1Lab;
@property (nonatomic, strong) UILabel *danWeiTitleLab;
@property (nonatomic, strong) UITextField *danWeiField;
@property (nonatomic, strong) UILabel *chengYunTitleLab;
@property (nonatomic, strong) UITextField *chengYunField;
@property (nonatomic, strong) UILabel *pieceTitleLab;
@property (nonatomic, strong) UITextField *pieceMinField;
@property (nonatomic, strong) UITextField *pieceMaxField;
@property (nonatomic, strong) UILabel *line2Lab;
@property (nonatomic, strong) UILabel *weightTitleLab;
@property (nonatomic, strong) UITextField *weightMinField;
@property (nonatomic, strong) UITextField *weightMaxField;
@property (nonatomic, strong) UILabel *line3Lab;
@property (nonatomic, strong) UILabel *volumeTitleLab;
@property (nonatomic, strong) UITextField *volumeMinField;
@property (nonatomic, strong) UITextField *volumeMaxField;
@property (nonatomic, strong) UILabel *line4Lab;
@property (nonatomic, strong) UILabel *timeTitleLab;
@property (nonatomic, strong) UITextField *beginField;
@property (nonatomic, strong) UITextField *endField;
@property (nonatomic, strong) UIButton *carBtn;
@property (nonatomic, strong) UIButton *beginBtn;
@property (nonatomic, strong) UIButton *endBtn;

@end

@implementation TaskManagerScreenViewCell

+ (instancetype)TaskManagerScreenViewCellWithTableView:(UITableView *)tableView {
    static NSString *cellID = @"TaskManagerScreenViewCell";
    TaskManagerScreenViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell = [[TaskManagerScreenViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
    }
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.backgroundColor = HexColor(0xffffff);
        CGFloat viewW = ScreenW - 90;
        self.noTitleLab = [[UILabel alloc] initWithFrame:CGRectMake(15, 0, viewW - 30, 17)];
        self.noTitleLab.textColor = HexColor(0x2B2C44);
        self.noTitleLab.font = BoldFontOfSize(16);
        self.noTitleLab.text = @"任务单号";
        [self.contentView addSubview:self.noTitleLab];
        
        self.noField = [[UITextField alloc] initWithFrame:CGRectMake(15, self.noTitleLab.nim_bottom + 10, viewW - 30, 32)];
        self.noField.backgroundColor = HexColor(0xF7F7FA);
        self.noField.textAlignment = NSTextAlignmentCenter;
        self.noField.layer.cornerRadius = 4;
        self.noField.font = [UIFont systemFontOfSize:15];
        self.noField.placeholder = @"请输入任务单号";
        [self.contentView addSubview:self.noField];
        [self.noField addTarget:self action:@selector(noFieldChange:) forControlEvents:UIControlEventEditingDidEnd];
        
        self.lineTitleLab = [[UILabel alloc] initWithFrame:CGRectMake(15, 20 + self.noField.nim_bottom, viewW - 30, 17)];
        self.lineTitleLab.textColor = HexColor(0x2B2C44);
        self.lineTitleLab.font = BoldFontOfSize(16);
        self.lineTitleLab.text = @"运输路线";
        [self.contentView addSubview:self.lineTitleLab];
        
        self.chuFaField = [[UITextField alloc] initWithFrame:CGRectMake(15, self.lineTitleLab.nim_bottom + 10, (viewW - 30 - 35) * 0.5, 32)];
        self.chuFaField.backgroundColor = HexColor(0xF7F7FA);
        self.chuFaField.textAlignment = NSTextAlignmentCenter;
        self.chuFaField.layer.cornerRadius = 4;
        self.chuFaField.font = [UIFont systemFontOfSize:15];
        self.chuFaField.placeholder = @"提货地";
        [self.contentView addSubview:self.chuFaField];
        [self.chuFaField addTarget:self action:@selector(chuFaFieldChange:) forControlEvents:UIControlEventEditingDidEnd];
        
        self.muDiField = [[UITextField alloc] initWithFrame:CGRectMake(self.chuFaField.nim_right + 35, self.lineTitleLab.nim_bottom + 10, (viewW - 30 - 35) * 0.5, 32)];
        self.muDiField.backgroundColor = HexColor(0xF7F7FA);
        self.muDiField.textAlignment = NSTextAlignmentCenter;
        self.muDiField.layer.cornerRadius = 4;
        self.muDiField.font = [UIFont systemFontOfSize:15];
        self.muDiField.placeholder = @"送货地";
        [self.contentView addSubview:self.muDiField];
        [self.muDiField addTarget:self action:@selector(muDiFieldChange:) forControlEvents:UIControlEventEditingDidEnd];
        
        self.line1Lab = [[UILabel alloc] initWithFrame:CGRectMake(self.chuFaField.nim_right + 10, self.chuFaField.nim_top + 15, 15, 2)];
        self.line1Lab.backgroundColor = HexColor(0xDBDCE6);
        [self.contentView addSubview:self.line1Lab];
        
        self.danWeiTitleLab = [[UILabel alloc] initWithFrame:CGRectMake(15, 20 + self.chuFaField.nim_bottom, viewW - 30, 17)];
        self.danWeiTitleLab.textColor = HexColor(0x2B2C44);
        self.danWeiTitleLab.font = BoldFontOfSize(16);
        self.danWeiTitleLab.text = @"任务来源";
        [self.contentView addSubview:self.danWeiTitleLab];
        
        self.danWeiField = [[UITextField alloc] initWithFrame:CGRectMake(15, self.danWeiTitleLab.nim_bottom + 10, viewW - 30, 32)];
        self.danWeiField.backgroundColor = HexColor(0xF7F7FA);
        self.danWeiField.textAlignment = NSTextAlignmentCenter;
        self.danWeiField.layer.cornerRadius = 4;
        self.danWeiField.font = [UIFont systemFontOfSize:15];
        self.danWeiField.placeholder = @"请输入";
        [self.contentView addSubview:self.danWeiField];
        [self.danWeiField addTarget:self action:@selector(danWeiFieldChange:) forControlEvents:UIControlEventEditingDidEnd];
        
        self.chengYunTitleLab = [[UILabel alloc] initWithFrame:CGRectMake(15, 20 + self.danWeiField.nim_bottom, viewW - 30, 17)];
        self.chengYunTitleLab.textColor = HexColor(0x2B2C44);
        self.chengYunTitleLab.font = BoldFontOfSize(16);
        self.chengYunTitleLab.text = @"车辆要求";
        [self.contentView addSubview:self.chengYunTitleLab];
        
        self.chengYunField = [[UITextField alloc] initWithFrame:CGRectMake(15, self.chengYunTitleLab.nim_bottom + 10, viewW - 30, 32)];
        self.chengYunField.backgroundColor = HexColor(0xF7F7FA);
        self.chengYunField.textAlignment = NSTextAlignmentCenter;
        self.chengYunField.layer.cornerRadius = 4;
        self.chengYunField.font = [UIFont systemFontOfSize:15];
        self.chengYunField.placeholder = @"请选择";
        [self.contentView addSubview:self.chengYunField];
        
        self.carBtn = [[UIButton alloc] initWithFrame:self.chengYunField.frame];
        [self.carBtn addTarget:self action:@selector(carClick) forControlEvents:UIControlEventTouchUpInside];
        [self.contentView addSubview:self.carBtn];
        
        self.pieceTitleLab = [[UILabel alloc] initWithFrame:CGRectMake(15, 20 + self.chengYunField.nim_bottom, viewW - 30, 17)];
        self.pieceTitleLab.textColor = HexColor(0x2B2C44);
        self.pieceTitleLab.font = BoldFontOfSize(16);
        self.pieceTitleLab.text = @"件数";
        [self.contentView addSubview:self.pieceTitleLab];
        
        self.pieceMinField = [[UITextField alloc] initWithFrame:CGRectMake(15, self.pieceTitleLab.nim_bottom + 10, (viewW - 30 - 35) * 0.5, 32)];
        self.pieceMinField.backgroundColor = HexColor(0xF7F7FA);
        self.pieceMinField.textAlignment = NSTextAlignmentCenter;
        self.pieceMinField.layer.cornerRadius = 4;
        self.pieceMinField.font = [UIFont systemFontOfSize:15];
        self.pieceMinField.placeholder = @"最小值";
        self.pieceMinField.keyboardType = UIKeyboardTypeNumberPad;
        [self.contentView addSubview:self.pieceMinField];
        [self.pieceMinField addTarget:self action:@selector(pieceMinFieldChange:) forControlEvents:UIControlEventEditingDidEnd];
        
        self.pieceMaxField = [[UITextField alloc] initWithFrame:CGRectMake(self.pieceMinField.nim_right + 35, self.pieceTitleLab.nim_bottom + 10, (viewW - 30 - 35) * 0.5, 32)];
        self.pieceMaxField.backgroundColor = HexColor(0xF7F7FA);
        self.pieceMaxField.textAlignment = NSTextAlignmentCenter;
        self.pieceMaxField.layer.cornerRadius = 4;
        self.pieceMaxField.font = [UIFont systemFontOfSize:15];
        self.pieceMaxField.placeholder = @"最大值";
        self.pieceMaxField.keyboardType = UIKeyboardTypeNumberPad;
        [self.contentView addSubview:self.pieceMaxField];
        [self.pieceMaxField addTarget:self action:@selector(pieceMaxFieldChange:) forControlEvents:UIControlEventEditingDidEnd];
        
        self.line2Lab = [[UILabel alloc] initWithFrame:CGRectMake(self.pieceMinField.nim_right + 10, self.pieceMinField.nim_top + 15, 15, 2)];
        self.line2Lab.backgroundColor = HexColor(0xDBDCE6);
        [self.contentView addSubview:self.line2Lab];
        
        self.weightTitleLab = [[UILabel alloc] initWithFrame:CGRectMake(15, 20 + self.pieceMinField.nim_bottom, viewW - 30, 17)];
        self.weightTitleLab.textColor = HexColor(0x2B2C44);
        self.weightTitleLab.font = BoldFontOfSize(16);
        self.weightTitleLab.text = @"货物重量(KG)";
        [self.contentView addSubview:self.weightTitleLab];
        
        self.weightMinField = [[UITextField alloc] initWithFrame:CGRectMake(15, self.weightTitleLab.nim_bottom + 10, (viewW - 30 - 35) * 0.5, 32)];
        self.weightMinField.backgroundColor = HexColor(0xF7F7FA);
        self.weightMinField.textAlignment = NSTextAlignmentCenter;
        self.weightMinField.layer.cornerRadius = 4;
        self.weightMinField.font = [UIFont systemFontOfSize:15];
        self.weightMinField.placeholder = @"最小值";
        self.weightMinField.keyboardType = UIKeyboardTypeDecimalPad;
        [self.contentView addSubview:self.weightMinField];
        [self.weightMinField addTarget:self action:@selector(weightMinFieldChange:) forControlEvents:UIControlEventEditingDidEnd];
        
        self.weightMaxField = [[UITextField alloc] initWithFrame:CGRectMake(self.weightMinField.nim_right + 35, self.weightTitleLab.nim_bottom + 10, (viewW - 30 - 35) * 0.5, 32)];
        self.weightMaxField.backgroundColor = HexColor(0xF7F7FA);
        self.weightMaxField.textAlignment = NSTextAlignmentCenter;
        self.weightMaxField.layer.cornerRadius = 4;
        self.weightMaxField.font = [UIFont systemFontOfSize:15];
        self.weightMaxField.placeholder = @"最大值";
        self.weightMaxField.keyboardType = UIKeyboardTypeDecimalPad;
        [self.contentView addSubview:self.weightMaxField];
        [self.weightMaxField addTarget:self action:@selector(weightMaxFieldChange:) forControlEvents:UIControlEventEditingDidEnd];
        
        self.line3Lab = [[UILabel alloc] initWithFrame:CGRectMake(self.weightMinField.nim_right + 10, self.weightMinField.nim_top + 15, 15, 2)];
        self.line3Lab.backgroundColor = HexColor(0xDBDCE6);
        [self.contentView addSubview:self.line3Lab];
        
        self.volumeTitleLab = [[UILabel alloc] initWithFrame:CGRectMake(15, 20 + self.weightMinField.nim_bottom, viewW - 30, 17)];
        self.volumeTitleLab.textColor = HexColor(0x2B2C44);
        self.volumeTitleLab.font = BoldFontOfSize(16);
        self.volumeTitleLab.text = @"货物体积(m³)";
        [self.contentView addSubview:self.volumeTitleLab];
        
        self.volumeMinField = [[UITextField alloc] initWithFrame:CGRectMake(15, self.volumeTitleLab.nim_bottom + 10, (viewW - 30 - 35) * 0.5, 32)];
        self.volumeMinField.backgroundColor = HexColor(0xF7F7FA);
        self.volumeMinField.textAlignment = NSTextAlignmentCenter;
        self.volumeMinField.layer.cornerRadius = 4;
        self.volumeMinField.font = [UIFont systemFontOfSize:15];
        self.volumeMinField.placeholder = @"最小值";
        self.volumeMinField.keyboardType = UIKeyboardTypeDecimalPad;
        [self.contentView addSubview:self.volumeMinField];
        [self.volumeMinField addTarget:self action:@selector(volumeMinFieldChange:) forControlEvents:UIControlEventEditingDidEnd];
        
        self.volumeMaxField = [[UITextField alloc] initWithFrame:CGRectMake(self.volumeMinField.nim_right + 35, self.volumeTitleLab.nim_bottom + 10, (viewW - 30 - 35) * 0.5, 32)];
        self.volumeMaxField.backgroundColor = HexColor(0xF7F7FA);
        self.volumeMaxField.textAlignment = NSTextAlignmentCenter;
        self.volumeMaxField.layer.cornerRadius = 4;
        self.volumeMaxField.font = [UIFont systemFontOfSize:15];
        self.volumeMaxField.placeholder = @"最大值";
        self.volumeMaxField.keyboardType = UIKeyboardTypeDecimalPad;
        [self.contentView addSubview:self.volumeMaxField];
        [self.volumeMaxField addTarget:self action:@selector(volumeMaxFieldChange:) forControlEvents:UIControlEventEditingDidEnd];
        
        self.line4Lab = [[UILabel alloc] initWithFrame:CGRectMake(self.volumeMinField.nim_right + 10, self.volumeMinField.nim_top + 15, 15, 2)];
        self.line4Lab.backgroundColor = HexColor(0xDBDCE6);
        [self.contentView addSubview:self.line4Lab];
        
        self.timeTitleLab = [[UILabel alloc] initWithFrame:CGRectMake(15, 20 + self.volumeMinField.nim_bottom, viewW - 30, 17)];
        self.timeTitleLab.textColor = HexColor(0x2B2C44);
        self.timeTitleLab.font = BoldFontOfSize(16);
        self.timeTitleLab.text = @"发布时间";
        [self.contentView addSubview:self.timeTitleLab];
        
        self.beginField = [[UITextField alloc] initWithFrame:CGRectMake(15, self.timeTitleLab.nim_bottom + 10, viewW - 30, 32)];
        self.beginField.backgroundColor = HexColor(0xF7F7FA);
        self.beginField.textAlignment = NSTextAlignmentCenter;
        self.beginField.layer.cornerRadius = 4;
        self.beginField.font = [UIFont systemFontOfSize:15];
        self.beginField.placeholder = @"起始时间";
        [self.contentView addSubview:self.beginField];
        
        self.endField = [[UITextField alloc] initWithFrame:CGRectMake(15, self.beginField.nim_bottom + 10, viewW - 30, 32)];
        self.endField.backgroundColor = HexColor(0xF7F7FA);
        self.endField.textAlignment = NSTextAlignmentCenter;
        self.endField.layer.cornerRadius = 4;
        self.endField.font = [UIFont systemFontOfSize:15];
        self.endField.placeholder = @"截止时间";
        [self.contentView addSubview:self.endField];
        
        self.beginBtn = [[UIButton alloc] initWithFrame:self.beginField.frame];
        [self.beginBtn addTarget:self action:@selector(beginClick) forControlEvents:UIControlEventTouchUpInside];
        [self.contentView addSubview:self.beginBtn];
        
        self.endBtn = [[UIButton alloc] initWithFrame:self.endField.frame];
        [self.endBtn addTarget:self action:@selector(endClick) forControlEvents:UIControlEventTouchUpInside];
        [self.contentView addSubview:self.endBtn];
        
        self.height = self.endField.nim_bottom + 20;
    }
    return self;
}

- (void)carClick {
    if (self.cheLiangBlock) {
        self.cheLiangBlock();
    }
}

- (void)beginClick {
    if (self.beginBlock) {
        self.beginBlock();
    }
}

- (void)endClick {
    if (self.endBlock) {
        self.endBlock();
    }
}

- (void)noFieldChange:(UITextField *)field {
    if (self.danHaoBlock) {
        self.danHaoBlock(field.text);
    }
}

- (void)chuFaFieldChange:(UITextField *)field {
    if (self.chuFaBlock) {
        self.chuFaBlock(field.text);
    }
}

- (void)muDiFieldChange:(UITextField *)field {
    if (self.muDiBlock) {
        self.muDiBlock(field.text);
    }
}

- (void)danWeiFieldChange:(UITextField *)field {
    if (self.laiYuanBlock) {
        self.laiYuanBlock(field.text);
    }
}

- (void)pieceMinFieldChange:(UITextField *)field {
    if (self.pieceMinBlock) {
        self.pieceMinBlock(field.text);
    }
}

- (void)pieceMaxFieldChange:(UITextField *)field {
    if (self.pieceMaxBlock) {
        self.pieceMaxBlock(field.text);
    }
}

- (void)weightMinFieldChange:(UITextField *)field {
    if (self.weightMinBlock) {
        self.weightMinBlock(field.text);
    }
}

- (void)weightMaxFieldChange:(UITextField *)field {
    if (self.weightMaxBlock) {
        self.weightMaxBlock(field.text);
    }
}

- (void)volumeMinFieldChange:(UITextField *)field {
    if (self.volumeMinBlock) {
        self.volumeMinBlock(field.text);
    }
}

- (void)volumeMaxFieldChange:(UITextField *)field {
    if (self.volumeMaxBlock) {
        self.volumeMaxBlock(field.text);
    }
}

-(void)setModel:(TaskManagerSearchModel *)model {
    _model = model;
    self.noField.text = model.the_num.length ? model.the_num : @"";
    self.chuFaField.text = model.s_city.length ? model.s_city : @"";
    self.muDiField.text = model.r_city.length ? model.r_city : @"";
    self.danWeiField.text = model.t_name.length ? model.t_name : @"";
    self.chengYunField.text = model.car_require_name.length ? model.car_require_name : @"";
    self.pieceMinField.text = model.pnum_min.length ? model.pnum_min : @"";
    self.pieceMaxField.text = model.pnum_max.length ? model.pnum_max : @"";
    self.weightMinField.text = model.weight_min.length ? model.weight_min : @"";
    self.weightMaxField.text = model.weight_max.length ? model.weight_max : @"";
    self.volumeMinField.text = model.volume_min.length ? model.volume_min : @"";
    self.volumeMaxField.text = model.volume_max.length ? model.volume_max : @"";
    self.beginField.text = model.strat_time.length ? model.strat_time : @"";
    self.endField.text = model.end_time.length ? model.end_time : @"";
}

@end
